fix: support batch broadcasting in JoinImageWithAlpha node#13309
fix: support batch broadcasting in JoinImageWithAlpha node#13309Abdulrehman-PIAIC80387 wants to merge 1 commit intoComfy-Org:masterfrom
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
✅ Files skipped from review due to trivial changes (1)
📝 WalkthroughWalkthroughThe 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Tip 💬 Introducing Slack Agent: The best way for teams to turn conversations into code.Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.
Built for teams:
One agent for your entire SDLC. Right inside Slack. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Review rate limit: 6/8 reviews remaining, refill in 12 minutes and 8 seconds.Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
comfy_extras/nodes_compositing.py (1)
205-210: Lock in the new broadcast behavior with a regression test.This changes
JoinImageWithAlphafrom overlap-only batching to broadcast batching, so please add or update coverage for bothN images + 1 maskand1 image + N masks.tests-unit/comfy_extras_test/image_stitch_test.py:27-47already shows the repo’s “larger batch wins” pattern for similar image ops.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@comfy_extras/nodes_compositing.py` around lines 205 - 210, JoinImageWithAlpha now broadcasts batches (larger batch wins) so add a regression test that asserts both broadcast cases: (a) N images + 1 mask and (b) 1 image + N masks produce outputs with batch size equal to max(N_images, N_masks) and that the per-item alpha channel matches the expected broadcasted mask values; locate the operator under test (JoinImageWithAlpha in nodes_compositing.py, which uses resize_mask and concatenates alpha) and follow the existing "larger batch wins" pattern from the repo’s image-stitch tests to create two unit tests that construct small synthetic tensors, run the operator, and assert output shape and channel content for both scenarios.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@comfy_extras/nodes_compositing.py`:
- Around line 205-210: JoinImageWithAlpha now broadcasts batches (larger batch
wins) so add a regression test that asserts both broadcast cases: (a) N images +
1 mask and (b) 1 image + N masks produce outputs with batch size equal to
max(N_images, N_masks) and that the per-item alpha channel matches the expected
broadcasted mask values; locate the operator under test (JoinImageWithAlpha in
nodes_compositing.py, which uses resize_mask and concatenates alpha) and follow
the existing "larger batch wins" pattern from the repo’s image-stitch tests to
create two unit tests that construct small synthetic tensors, run the operator,
and assert output shape and channel content for both scenarios.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 18ced04d-feb6-46ff-9ad5-728129bdea09
📒 Files selected for processing (1)
comfy_extras/nodes_compositing.py
|
@Abdulrehman-PIAIC80387 thank you for your contribution, this looks good. Could you please address the error from the CI pipeline and update your PR? Thanks |
467b0c5 to
bce9cd6
Compare
|
@alexisrolland Done — I removed the Co-authored-by trailer from the commit message and force-pushed. Thanks for the review! |
bce9cd6 to
5c2ae6f
Compare
|
Hey, thank you for raising the issue and for the suggested fix. However I would rather do this using the existing |
|
Agree with @kijai the |



Summary
Fixes #12580
Problem
The
Join Image with Alphanode only returns a single image when given a batch of images with a single alpha mask.Root cause: In
comfy_extras/nodes_compositing.pyline 205, the batch size was calculated usingmin(len(image), len(alpha)). When a user passes a batch of 4 images with a single alpha mask,min(4, 1) = 1, so only one image is produced.This is inconsistent with every other compositing node in ComfyUI (e.g.,
ImageCompositeMasked), which correctly broadcasts the shorter input to match the longer one.Fix
Changed
comfy_extras/nodes_compositing.pyto usemax()instead ofmin()for batch size, with modulo indexing (i % len(...)) to repeat the shorter input:This handles all cases correctly: